#!/bin/bash
set -e
cd $(dirname "$0")/..
pwd

DEXDUMP=(~/sdk/build-tools/*/dexdump.exe)
DEXDUMP=${DEXDUMP[0]}
if [[ ! -f $DEXDUMP ]]; then
    echo "Dexdump not found in ~/sdk"
    exit 1
fi

APP=SampleApp
BUILD=$APP/build

if [[ "$1" != "--keep" ]]; then 
    rm -rfv $BUILD;
else
    rm -rfv $BUILD/bak
    rm -rfv $BUILD/_*dex.txt
fi
mkdir -p $BUILD

echo "## Start gradlew assemble for release"
./gradlew.bat test assembleRelease 2>&1 | tee $BUILD/_gradle_release_log.txt

APK=$BUILD/apk/$APP-release-unsigned.apk
cp -v $APK distrib/
